package Admin;

import JDBCutil.JDBCUtil;
import bean.SelectCourse;

import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.awt.*;
import java.text.ParseException;
import java.util.List;
/*
 * Created by JFormDesigner on Thu Aug 08 09:46:26 CST 2024
 */


/**
 * @author 29454
 */
public class ShowSelectCourse extends JPanel {
    public ShowSelectCourse() throws Exception {
        try {
            initComponents();
            initData();
        }
        catch (ParseException e1) {
            e1.printStackTrace();
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new RuntimeException(ex);
        }

    }

    public static JTable getTable1(){
        return table1;
    }

    private void initData() throws Exception {
        DefaultTableModel model = (DefaultTableModel) table1.getModel();
        List<SelectCourse> cs = JDBCUtil.getSelectCourseList();
        for (int i = 0; i < cs.size(); i++) {
            SelectCourse c = cs.get(i);
            model.addRow(new Object[]{c.getCourseid(),c.getStudentid(),c.getTeacherid(),c.getMark()});
        }
        table1.repaint();
    }
    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents  @formatter:off
        scrollPane1 = new JScrollPane();
        table1 = new JTable();
        table1.setModel(new DefaultTableModel(
                new Object [][] {},
                new String [] {"课程号", "学生学号", "教师工号","分数"} // 列名
        ));


        //======== this ========
        setLayout(null);

        //======== scrollPane1 ========
        {
            scrollPane1.setViewportView(table1);
        }
        add(scrollPane1);
        scrollPane1.setBounds(0, 0, 1700, 850);

        {
            // compute preferred size
            Dimension preferredSize = new Dimension();
            for(int i = 0; i < getComponentCount(); i++) {
                Rectangle bounds = getComponent(i).getBounds();
                preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
            }
            Insets insets = getInsets();
            preferredSize.width += insets.right;
            preferredSize.height += insets.bottom;
            setMinimumSize(preferredSize);
            setPreferredSize(preferredSize);
        }
        // JFormDesigner - End of component initialization  //GEN-END:initComponents  @formatter:on
    }

//    private void initData1(Student student) throws Exception {
//        DefaultTableModel model = (DefaultTableModel) table1.getModel();
//            model.addRow(new Object[]{student.getUserid(),student.getUsername(),student.getSex(),student.getBirthyear(),student.getGrade(),student.getCollege(),student.getSubject(),student.getClasses()});
//        }
//
//    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables  @formatter:off
    private JScrollPane scrollPane1;
    private static JTable table1;
    // JFormDesigner - End of variables declaration  //GEN-END:variables  @formatter:on
}
